﻿@model List<OrderHistory>
@{ ViewBag.Title = "Order History"; }

@if (Model.Count > 0)
{
    <p>Below are the orders placed by all users of the system.</p>
    <table class="wide">
        <thead>
            <tr>
                <th>Transaction ID</th>
                <th>Date</th>
                <th>Status</th>
                <th>User</th>
                <th>Total Cost</th>
                <th>Items</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var order in Model)
            {
                var user = new UserProfile(order.User);
                
                <tr>
                    <td>@order.PayPalTransaction</td>
                    <td>@order.DatePosted</td>
                    <td>@order.PayPalResult</td>
                    <td>@Html.ActionLink(user.NameFormatted(), "EditProfile", "Account", new { id = user.UserName }, new { target = "_blank" })</td>
                    <td>@String.Format("{0:c}", order.TotalCost)</td>
                    <td>
                        <ul class="orderHist">
                            @foreach (var p in order.Products)
                            {
                                <li>@p.LinkToItem(Html, p.Title)</li>
                            }
                        </ul>
                    </td>
                </tr>
            }
        </tbody>
    </table>
}
else
{
    <p>No orders have been processed by the system.</p>
}
